<?php

namespace app\admin\model\crm;

use think\Model;


class Orderck extends Model
{

    

    

    // 表名
    protected $name = 'crm_orderck';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    protected static function init()
    {
     
        self::beforeInsert(function ($row) {
            if (!isset($row['admin_id']) || !$row['admin_id']) {
                $admin_id = session('admin.id');
                $row['admin_id'] = $admin_id ? $admin_id : 0;
                $row['order_no'] = 'CK'.date('YmdHis').($admin_id ? $admin_id : 0);
            }
        });
    }     







    public function gongyingshang()
    {
        return $this->belongsTo('app\admin\model\pifa\Gongyingshang', 'gongyingshang_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
